package com.micro.ai.template.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.ai.template.entity.WorkflowExecution;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 工作流执行Mapper
 *
 * @author micro-ai
 * @since 0.0.1
 */
@Mapper
public interface WorkflowExecutionMapper extends BaseMapper<WorkflowExecution> {

    /**
     * 根据工作流ID查询执行记录
     */
    @Select("SELECT * FROM workflow_executions WHERE workflow_id = #{workflowId} ORDER BY created_at DESC LIMIT #{limit}")
    List<WorkflowExecution> selectByWorkflowId(@Param("workflowId") String workflowId, @Param("limit") Integer limit);

    /**
     * 根据状态查询执行记录
     */
    @Select("SELECT * FROM workflow_executions WHERE workflow_id = #{workflowId} AND status = #{status} ORDER BY created_at DESC")
    List<WorkflowExecution> selectByStatus(@Param("workflowId") String workflowId, @Param("status") String status);

    /**
     * 统计工作流执行次数
     */
    @Select("SELECT COUNT(*) FROM workflow_executions WHERE workflow_id = #{workflowId}")
    Integer countByWorkflowId(@Param("workflowId") String workflowId);
}

